package cn.fruitmarket.goods;

import lombok.Data;

@Data
public class Fruit {
    private String name;
    private double price;
    public Fruit(String name,double price) throws Exception{
        if(price<=0) {
            throw new Exception("价格必须大于0");
        }
        this.price = price;
        this.name = name;
    }
    @Override
    public int hashCode(){
        return name.hashCode();
    }
    @Override
    public boolean equals(Object obj) {
        if(this == obj) {
            return  true;
        }
        if(obj == null) {
            return false;
        }
        if(getClass() != obj.getClass()){
            return  false;
        }
        Fruit fruit = (Fruit) obj;
        if(name == null) {
            if(fruit.name != null) {
                return false;
            }
        }else if(!name.equals(fruit.name)) {
            return false;
        }
        return true;
    }
}
